#region Summary

// 
// Owner : JackieHan 
// 
// Solution : DailyCollection 
// 
// Project : Jackie.Utility.Condition.Test
// 
// File : TestExpression.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 测试词法分析
// 
// History : 
//			2011-05-20 15:54:56	    Create 
// 

#endregion

#region Using

using System;
using Jackie.Utility.Condition.Domain.Define;
using Jackie.Utility.Condition.Domain.Interface;
using Jackie.Utility.CustomExtension;
using NUnit.Framework;
using System.Linq;

#endregion

namespace Jackie.Utility.Condition.Test.WordAnalyse
{
    /// <summary> 
    /// 测试词法分析
    /// </summary>
    [TestFixture]
    public class TestNumberic
    {

        private IWordAnalyser wordAnalyser;

        [SetUp]
        public void SetUp()
        {
            wordAnalyser = new DefaultWordsAnalyser();
        }
        
        [Test]
        public void Test()
        {
            var express = "123";
            Numberic(express);

            express = "1234.12";
            Numberic(express);

            express = "1234.";
            Numberic(express);

            express = "1234.bb";
            NumbericWithError(express);
        }

        private void NumbericWithError(string code)
        {
            var results = wordAnalyser.Analyse(code);

            results.ForEach(Console.WriteLine);

            Assert.Greater(results.Count, 1);
        }

        private void Numberic(string code)
        {
            var results = wordAnalyser.Analyse(code);

            results.ForEach(Console.WriteLine);

            Assert.AreEqual(results.Count, 1);

            var result = results[0];
            Assert.IsInstanceOf(typeof(Numberic), result.DefineType);
            Assert.AreEqual(code, result.Value);
        }
    }
}